import { CallHandler, ExecutionContext, Injectable, Logger, NestInterceptor } from '@nestjs/common'
import { Request } from 'express'
import { map } from 'rxjs/operators'
import { HttpStatus } from '@nestjs/common'

@Injectable()
export class TransformInterceptor implements NestInterceptor {
  intercept(context: ExecutionContext, next: CallHandler) {
    context.switchToHttp().getResponse().status(200)
    return next.handle().pipe(
      map((data) => {
        return {
          code: HttpStatus.OK,
          data,
        }
      }),
    )
  }
}
